package ui;

import com.gzbit.calculator.simplefactory.bll.Operation;
import com.gzbit.calculator.simplefactory.factory.SimpleFactory;

import java.util.Scanner;

//纯粹的界面逻辑代码
public class View {
    private int numberA, numberB;
    private String operator;
    //完成具体的业务逻辑：计算
    private Operation operation;

    public View(int numberA, int numberB, String operator) {
        this.numberA = numberA;
        this.numberB = numberB;
        this.operator = operator;
        //使用简单工厂生产运算类对象
        operation = SimpleFactory.getOperation(operator);
    }

    public View() {
        //使用简单工厂生产运算类对象
        operation = SimpleFactory.getOperation(operator);
    }

    public void setValue(int numberA, int numberB, String operator) {
        this.numberA = numberA;
        this.numberB = numberB;
        this.operator = operator;
    }

    public int getResult() throws Exception {
        int result = operation.getResult();
        return result;
    }

    public void inputData() {
        Scanner scanner = new Scanner(System.in);
        this.numberA = scanner.nextInt();
        this.numberB = scanner.nextInt();
        this.operator = scanner.next();
    }

    public void outputResult() throws Exception {
        System.out.println(this.getResult());
    }
}
